package com.gg.admin.user.contorller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.gg.dao.AdminUserMapper;
import com.gg.entity.User;

import helpers.baseservlet.BaseServlet;


@WebServlet("/admin/AdminVerifyServlet")
public class AdminVerifyServlet extends BaseServlet {
	@Autowired
	private  AdminUserMapper  adminUserMapper;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println(12345);
		String   key =  request.getParameter("key");
		User   thisuser =   (User) request.getSession().getAttribute("thisuser");
		if("username".equals(key)) {
			String   username =  request.getParameter("username");
			User  user =  adminUserMapper.selectUserByUsername(username);
			if(user==null) {
				response.getWriter().print(true);
			}else {
				
				String   preusername =  thisuser.getUsername();
				if(preusername.equals(username)) {
					response.getWriter().print(false);
					return  ;
				}
				response.getWriter().print(true);
			}
			
		}else if("email".equals(key)) {
			String  email  = request.getParameter("email");
			User  user  = adminUserMapper.selectUserByEmail(email);
			if(user==null) {
				response.getWriter().print(true);
			}else {
				String   preemail =  thisuser.getEmail();
				if(preemail.equals(email)) {
					response.getWriter().print(true);
					return  ;
				}
				response.getWriter().print(false);
			}
		}else if("tel".equals(key)) {
			String  tel  = request.getParameter("tel");
			User  user  = adminUserMapper.selectUserByTel(tel);
			if(user==null) {
				response.getWriter().print(true);
			}else {
				String   pretel =  thisuser.getTel();
				if(pretel.equals(tel)) {
					response.getWriter().print(true);
					return  ;
				}
				response.getWriter().print(false);
			}
		}
		
	}

}
